package com.sgb.member.view_model;



import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.sgb.member.MemberConfig;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MemberModifyViewModel extends ViewModel{
    public MutableLiveData<String> msgLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> isSuccessLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> isLoadLiveData = new MutableLiveData<>();
    public void getMemberTypeList( List<CommonPopEntity> memberTypes,String contacts, String level,
                                   String phone,String relation,String no,String checkType) {
        // 0 供方 1需方
        isLoadLiveData.postValue(true);
        Map<String, Object> map = new HashMap<>();
        map.put("contacts", contacts);
        List<String> ls_no = new ArrayList<>();
        for (int i = 0; i < memberTypes.size(); i++) {
            ls_no.add(memberTypes.get(i).getNo());
        }
        map.put("firstCategory", ls_no);
        map.put("level", level);
        map.put("relation", relation);
        map.put("phone", phone);
        map.put("no", no);
        map.put("memberType", Integer.parseInt(checkType)+1);

        MemberConfig.getInstance().getApi().updateMember(map).enqueue(new ICallBack<BaseEntity<BaseEntity>>() {
            @Override
            public void onSuccess(BaseEntity<BaseEntity> data) {
                isLoadLiveData.postValue(false);
                if (data.getState().equals("ok")) {
                    isSuccessLiveData.setValue(true);
                }else {
                    msgLiveData.postValue("修改失败!");
                }
            }

            @Override
            public void onFail() {
                isLoadLiveData.postValue(false);
                msgLiveData.postValue("请求失败!");
            }
        });
    }
}
